<template>
 <view class="main">
   <view class="logo">
	 <view class="ilist" @click="myitem">
		<view class="ilist1"></view> 
		<view class="ilist2"></view> 
	 </view>
	 <image src="https://ppp.new.zeroitem.cn/ppp/logo.png" class="img1"></image>   
   </view>

   <view class="part" style="margin-top:40rpx" @click="jumpcal">
	  <view class="tip1"></view>
	  <view class="rq">{{pdate}}</view>
	  <image src="https://ppp.new.zeroitem.cn/ppp/rq.png" class="img2"></image>
   </view>
   
   
  <view class="pssj"  v-if="yx.pssj<3">
	  <view class="fname fname2 fname3" style="padding-left:0rpx">
		<view class="tip1"style="margin-right:10rpx"></view>  
	    选择当日可安排的拍摄时间
	  </view>
  
	  <block v-if="yx.pssj==1">
		  <view class="sstime" v-if="n1!=1" @click="settime(1)" :class="timep==1 ? 'pcur' : ''">上午 （08:00-12:00)</view>
		  <view class="sstime" v-if="n2!=1" @click="settime(2)" :class="timep==2 ? 'pcur' : ''">下午 （13:00-17:00)</view>
		  <view class="sstime" v-if="n3!=1" @click="settime(3)" :class="timep==3 ? 'pcur' : ''">晚上 （18:00-22:00)</view>
	  </block>	  
	  
	    <block v-if="yx.pssj==2">
			  <view class="sstime" style="width:95%;font-size:28rpx" v-if="n1!=1 && n2!=1"  @click="settime(4)" :class="timep==4 ? 'pcur' : ''">上全天 （08:00-12:00）（13:00-17:00）</view>
			  <view class="sstime"  style="width:95%;font-size:28rpx" v-if="n2!=1 && n3!=1" @click="settime(5)" :class="timep==5 ? 'pcur' : ''">下全天 （13:00-17:00）（18:00-22:00）</view>
	    </block>  
  </view> 
   
 <view class="part" style="margin-top:20rpx">
 	  <view class="tip1"></view>
 	  <view class="dw" @click="dingwei">
		{{dwmsg}}
		<image src="https://ppp.new.zeroitem.cn/ppp/dw.png" class="img3"></image>
	  </view>
 	  <input type="text" placeholder="输入具体地址及门牌" class="jtdz" v-model="jtdz"/>
 </view>  
   
  <view class="part1" style="margin-top:20rpx">
	  <view class="part1-1">
		 <view class="tip1"></view> 
		 <input type="text" placeholder="输入联系人" class="user" v-model="xm"/>
	  </view>
	  <view class="part1-2">
		 <input type="text" placeholder="输入联系电话" class="phone" v-model="phone"/>  
	  </view>
  </view>
  <view class="fname fname2">根据视频拍以下同款</view>	
  <view class="pthp">
	<video :src="yx.vsrc" class="videoc" objectFit="cover"></video> 
	<image src="https://ppp.new.zeroitem.cn/ppp/jja.png" class="jja"></image>
	<view class="face">
	 <image :src="yx.avatar" class="face1"></image>
	 <view class="fname">{{yx.nickname}}</view>	 
	</view>
  </view>
  <view class="qrbtn" @click="submitorder">
	 <image src="https://ppp.new.zeroitem.cn/ppp/car2.png" class="img6"></image>
     <view class="qtxt">确认下单</view>
   </view>
 
 </view>
</template>
<script>
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		toLogin
	} from '@/utils/login'
	
	import {
		loadingFun,
		menuJump
	} from '@/utils/tools'	
	
    import {
		loadingType
	} from '@/utils/type'
	
    import {
	  submitorder,yxdetail,pppset
	} from '@/api/ppp'	
	/***
    import {
	  uploadFileToTencentClound
	} from '@/js_sdk/COS'
	*/
	const app = getApp()
	export default {
		data() {
			return {
			 dwmsg:"定位",
	         tmode:0,
			 showt:0,
			 slice_type:2,
			 jtdz:"",
			 xm:"",
			 phone:"",
			 address:"",
			 latitude:"",
			 longitude:"",
			 wfile:"",
			 timep:0,
			 pstype:2,
			 vname:"",
			 showr:false,
			 show: false,
			 total_price:0,
			 stime1:"",
			 stime2:"",
			 plink:"",
			 remark:"拍摄同款",
			 pdate:"拍摄日期",
			 zt:'',
			 n1:0,
			 n2:0,
			 n3:0,
			 startDate:"2021-12-30",
			 yid:0,
			 oid:0,
			 yx:[],
			 pppset:[]
			}
		},
		onLoad(options) {
		  if(options.id!=0 && options.id!=undefined){
		     var yid=options.id;
		     this.yid=yid;
		     this.getyxdetail(yid,0);
		   }
		   if(options.oid!=0 && options.oid!=undefined){
		      var oid=options.oid;
		      this.oid=oid;
		      this.getyxdetail(oid,1);
		    }
		},
		onShow() {
         this.getpppset();
		},

		onReachBottom() {
	    
		},
		onPullDownRefresh() {

		},

		methods: {
		async getpppset(){
		  var that=this;
		  const{code,msg,data,
		  }= await pppset({});
		  if(code==1){
			that.pppset=data;
		  }	
		},	
		jumpcal(){
		 var uid=this.yx.uid;
		 var yid=this.yid;
		 uni.navigateTo({
		 	url:"/pages/ppp/order/pcalendar?uid="+uid+'&yid='+yid
		 }) 
		},
		setpadte(pdate){
		  this.pdate=pdate;	
		},
	     jumpback(){
			  uni.navigateBack();
		  },
		  xzsc(){
			this.showt=1; 
			this.tmode=1;
		  },
		  showtmode(tmode){
			this.tmode=tmode; 
			this.timep=0;
		  },
		  setzt(zt){
			var n1=zt.substr(0,1);
			var n2=zt.substr(1,1);
			var n3=zt.substr(2,1);
		    this.n1=n1;
			this.n2=n2;
			this.n3=n3;
			this.timep=0;
			this.zt=zt;
		  },
		  settime(tp){
			if(this.zt==''){
			  uni.showToast({icon:'none',title:'请先选择日期'});	
			  return false;
			}
			this.timep=tp;  
		  },
		  setpstype(type){
			this.pstype=type;  
		  },
		  bindDateChange(e){
		    this.pdate=e.detail.value; 
		  },
		  bindTimeChange(e){
		    console.log(e);
		  },
		  tjbz(){ this.showt=2;},
		  tjbz1(){ this.showt=0;},
		  tjckp(){this.showt=3;},
		  show_slice_type(type){this.slice_type=type;},
		  bindTimeChange1(e){
		   var stime1=e.detail.value; 
		   this.stime1=stime1;
		   console.log(this.stime1);
		  },
		  bindTimeChange2(e){
		   var stime2=e.detail.value; 
		   this.stime2=stime2;
		  },
		 async getyxdetail(yid,flag){
			const{
			  code,
			   msg,
			   data
			}= await yxdetail({id:yid,flag:flag}); 
			if(code==1){
			  this.yx=data;this.vname=data.vname;
			  if(this.yx.pssj>=3){this.timep=6;}
			  this.total_price=data.ckjg;
			}
		 },
		 async submitorder(){
			  if (!this.isLogin) return toLogin();
			  var pdate=this.pdate;
			  if(pdate=='拍摄日期'){
				uni.showToast({title:"请选择拍摄日期",icon:"none"});
				return false;  
			  }
		
			  if(this.yx.pssj>=3){this.timep=6;}
			  if(this.timep==0){
				uni.showToast({title:"请选择拍摄时间段",icon:"none"});
				return false;    
			  }
			  var address=this.address;
			  if(address==''){
				uni.showToast({title:"请定位选择拍摄地址",icon:"none"});
				return false;  
			  }	
			  var dz=address+this.jtdz;
			  var xm=this.xm;
			  if(xm==''){
				uni.showToast({title:"请填写联系人",icon:"none"});
				return false;    
			  }
			  var phone=this.phone;
			  if(phone==''){
			  	uni.showToast({title:"请填写联系电话",icon:"none"});
			  	return false;    
			  }
			  var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
			   if (!myreg.test(phone)) {
			     uni.showToast({title:"请输入有效的手机号码",icon:"none"});
			     return false;  
			   }
			   var odata={
				 pdate:pdate,address:address,
				 jtdz:dz,xm:xm,phone:phone,
				 timep:this.timep,pstype:this.pstype,
				 total_price:this.total_price,otype:2,
				 lat:this.latitude,lng:this.longitude,pthid:this.yid,poid:this.oid,
				 slice_type:this.slice_type,vname:this.vname
			   };
			  const{
				code,
				msg,
				data,
			  }= await submitorder(odata);
			  if(code==1){
				uni.navigateTo({
					url:"/pages/ppp/index/orderConfire?oid="+data.id
				})  
			  }
		},  
		jumpmenu(kn){
		if(kn==1){
		  uni.redirectTo({
			 url:"/pages/ppp/index/order"
		  })
		 }	
		 if(kn==2){
		   uni.redirectTo({
		 	 url:"/pages/ppp/index/drps"
		   })
		  }	
		 if(kn==3){
		   uni.redirectTo({
		 	 url:"/pages/ppp/index/dzxx"
		   })
		  }	
		 if(kn==4){
		   uni.redirectTo({
		 	 url:"/pages/ppp/index/dqdd"
		   })
		  }					
		  
		},
		tjslice(){
		 this.showt=2;	
		},
		myitem(){
		 uni.navigateTo({
		 	url:"/pages/ppp/my/index"
		 })	
		},
		dingwei(){
			       var that=this;
					uni.chooseLocation({
						success:(res)=> {
						  var address=res.address;
						  var ppp_area=that.pppset.ppp_area;
						  var cselect=0;
						  ppp_area.forEach(function(item){
              				if(address.indexOf(item)!=-1){ 
              				  cselect=1;
              				}
                          });
						 if(cselect!=1){
							this.dwmsg='定位';
							this.address='';
							this.latitude='';
							this.longitude='';
							uni.showToast({icon:'none',title:'暂不支持该拍摄城市，请重新选择'});  
						  }else{
						   this.address=res.address;
						   this.latitude=res.latitude;
						   this.longitude=res.longitude;
						   this.dwmsg='已选';
						   }
						  //this.jtdz=res.address;
						},
						fail:()=>{
							// 如果用uni.chooseLocation没有获取到地理位置，则需要获取当前的授权信息，判断是否有地理授权信息
							uni.getSetting({
								success: (res) => {
									console.log(res);
									var status = res.authSetting;
									if(!status['scope.userLocation']){
									// 如果授权信息中没有地理位置的授权，则需要弹窗提示用户需要授权地理信息
										uni.showModal({
											title:"是否授权当前位置",
											content:"需要获取您的地理位置，请确认授权，否则地图功能将无法使用",
											success:(tip)=>{
												if(tip.confirm){
												// 如果用户同意授权地理信息，则打开授权设置页面，判断用户的操作
													uni.openSetting({
														success:(data)=>{
														// 如果用户授权了地理信息在，则提示授权成功
															if(data.authSetting['scope.userLocation']===true){
																uni.showToast({
																	title:"授权成功",
																	icon:"success",
																	duration:1000
																})
																// 授权成功后，然后再次chooseLocation获取信息
																uni.chooseLocation({
																	success: (res) => {
																		console.log("详细地址",res);
																		// this.getRegionFn(res);
																	}
																})
															}else{
																uni.showToast({
																	title:"授权失败",
																	icon:"none",
																	duration:1000
																})
															}
														}
													})
												}
											}
										})
									}
								},
								fail: (res) => {
									uni.showToast({
										title:"调用授权窗口失败",
										icon:"none",
										duration:1000
									})
								}
							})
						}
					});
				}
		
		},
		computed: {
			...mapGetters(['isLogin']),
		}
	}
</script>
<style lang="scss">  
@import "./phhorder.css";	
</style>


